package org.shiro.service.Impl;

import org.shiro.dao.RolePermissionMapper;
import org.shiro.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @author HKC
 */
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
@Service
public class RolePermissionServiceImpl implements RolePermissionService {

  @Autowired private RolePermissionMapper rolePermissionMapper;

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public int insertPermission(Long roleId, List<Long> permissionIds) {
    Assert.notNull(roleId,"参数错误");
    Assert.notNull(permissionIds,"参数错误");
    int res = rolePermissionMapper.insertPermission(roleId,permissionIds);
    if (res > 0){
      return res;
    }
    return 0;
  }

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public int insertRole(List<Long> roleIds, Long permissionId) {
    return 0;
  }

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  @Override
  public int deleteByRoleId(Long roleId) {
    return 0;
  }
}
